package com.multithreading.chart1.interrupte;

/**
 * 比较interrupted()和isinterrupted()
 * @author chenqb
 */
public class InterruptedAndIsinterrupted {
    public static void main(String[] args) throws InterruptedException{
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
//                for (;;){}
                while (!Thread.interrupted()){

                }
                System.out.println("threadOne isInterrupted:"+Thread.currentThread().isInterrupted());
            }
        });
        //启动线程  线程死锁
        threadOne.start();
        //设置中断标志
        threadOne.interrupt();
        //获取中断标志
        System.out.println("isInterrupted:"+threadOne.isInterrupted());
        //获取中断标志并重置
        System.out.println("isInterrupted:"+ Thread.interrupted());
        //获取中断标志并重置
        System.out.println("isInterrupted:"+Thread.interrupted());
        //获取中断标志
        System.out.println("isInterrupted:"+threadOne.isInterrupted());

        threadOne.join();

        System.out.println("main thread is over!");


    }
}
